-- User: chenyiqun
local redis = require "resty.redis"

local function close_redis(red)
    if not red then
        return
    end
    local ok, err = red:close()
    if not ok then
        ngx.say("close redis error : ", err)
    end
end

local red = redis:new()
red:set_timeout(1000) -- 1 sec

local ok,err = red:connect("127.0.0.1",6379)
if not ok then
    ngx.say("failed to connection:",err)
    return close_redis(red)
end

local res,err = red:get("dog")
if not res then
    ngx.say("failed to get dog:",err)
    return close_redis(red)
end


if res == ngx.null then
    ngx.say("key not found")
    return close_redis(red)
end

ngx.say("msg : ", res)
close_redis(red)


